<template>
    <div class="SendResume">
        <el-dialog title="申请职位" width="350px" :visible.sync="SendResumeFlag" @open="resumeList" @close="SendResumeClose"
                   :destroy-on-close="true">
            <div class="box">
                <div class="title">请选择简历</div>
                <el-select v-model="resume" placeholder="请选择要投递的简历" @change="resumeChange">
                    <el-option v-for="(item,index) in list" :key="index" :label="item.resumeName"
                               :value="item.id"></el-option>
                </el-select>

                <div class="adjust">
                    <span class="fl">职位调剂：</span>
                    <el-switch class="fr" v-model="adjustFlag" active-text="同意" inactive-text="不同意" active-value="1"
                               inactive-value="2"></el-switch>
                </div>

                <div class="btns">
                    <el-button class="btn" @click="lookResume">预览简历</el-button>
                    <el-button type="primary" class="btn" @click="submit">立即投递</el-button>
                </div>
            </div>
        </el-dialog>
        <el-dialog title="" width="400px" :visible.sync="successFlag" @close="successClose">
            <div class="box1">
                <div class="title"><i class="el-icon-circle-check"></i>提交成功</div>
                <p></p>
                <p><img src="../assets/qr.jpg"></p>
                <p>关注公众号，获取更多【国央企、事业单位】招聘信息！</p>
            </div>
        </el-dialog>
    </div>
</template>

<script>
import {postResume, resumeList} from '@/api/api'

export default {
    //组件注入
    components: {},
    //存放数据
    data() {
        return {
            SendResumeFlag: false,
            resume: '',//选择的简历
            successFlag: false,
            list: [],
            resumeId: '',
            adjustFlag: '1', // 调剂标识 1 = 同意 2 = 不同意
            resumeType: null,
            resumeLanguage: '',
            LookEnclosureFlag: false,
        }
    },
    //接受父组件传递的值
    props: ['SendResume', 'JobId'],
    //监控data中的数据变化
    watch: {
        SendResume(newVaL) {
            this.SendResumeFlag = newVaL
        }
    },
    //方法集合
    methods: {
        //弹出关闭
        SendResumeClose() {
            this.$emit('SendResumeClose')
        },
        //提交
        submit() {
            if (this.resumeId) {
                postResume({
                    'jobId': this.JobId,
                    'resumeId': this.resumeId,
                    'language': this.resumeLanguage,
                    'companyId': '',
                    'r10': this.adjustFlag, // 调剂标识 1 = 同意 2 = 不同意
                }).then(res => {
                    if (res.code == 200) {
                        this.SendResumeFlag = false
                        this.successFlag = true
                    } else {
                        // this.$message.error(res.message);


                        this.SendResumeFlag = false
                        this.$confirm(res.message, '提示', {
                            confirmButtonText: '前去编辑简历',
                            cancelButtonText: '取消',
                            type: 'warning'
                        }).then(() => {
                            this.SendResumeFlag = false
                            //路由到简历页面（）
                            if (this.resumeLanguage == 1) {
                                this.$router.push({name: 'PersonResumeEn', query: {id: this.resumeId}})
                            } else {
                                this.$router.push({name: 'PersonResume'})
                            }

                            //新窗口打开
                            //     let url = this.$router.resolve({
                            //         name:'PersonResume'
                            //     });
                            //   window.open(url.href, '_blank');


                            // <router-link :to="{name:'PersonResume'}" class="btnResume">简历</router-link>
                            // this.$message({
                            //     type: 'success',
                            //     message: '删除成功!'
                            // });
                        }).catch(() => {
                            this.SendResumeFlag = true
                            // this.$message({
                            //     type: 'info',
                            //     message: '已取消删除'
                            // });
                        });


                    }
                });
            } else {
                this.$message.error('请选择要投递的简历');
            }
        },
        //弹出关闭
        successClose() {
            this.successFlag = false
        },
        //选择简历
        resumeChange(id) {
            this.resumeId = id
            for (let i in this.list) {
                if (this.list[i].id == this.resumeId) {
                    this.resumeType = this.list[i].type
                    this.resumeLanguage = this.list[i].lanType
                }
            }
        },
        //预览简历
        lookResume() {
            if (this.resumeId) {
                if (this.resumeLanguage == 0) {
                    let routeData = this.$router.resolve({name: 'PersonResumeLook', query: {id: this.resumeId}})
                    window.open(routeData.href, '_blank');
                } else if (this.resumeLanguage == 1) {
                    let routeData = this.$router.resolve({name: 'PersonResumeEnLook', query: {id: this.resumeId}})
                    window.open(routeData.href, '_blank');
                    // this.LookEnclosure()
                }
            } else {
                this.$message.error('请选择要预览的简历');
            }
        },
        //预览附件简历
        LookEnclosure() {
            this.$emit("LookEnclosure", {LookEnclosureFlag: true})
        },
        resumeList() {
            //判断登录状态
            if (this.userLoginFlag1()) {
                resumeList({}, false).then(res => {
                    if (res.code == 200) {
                        localStorage.removeItem('resumeEnclosure')
                        let list = res.result.records
                        for (let i in list) {
                            if (list[i].updateTime) {
                                list[i].updateTime = list[i].updateTime.replace(/\-/g, ".")
                                list[i].updateTime = list[i].updateTime.split(' ')[0]
                            }
                            if (list[i].lanType == 0 && list[i].type == 1) {
                                localStorage.setItem('resumeEnclosure', JSON.stringify(list[i]))
                            }
                            this.list = list
                        }
                    }
                });
            }
        }
    },
    //生命周期 - 创建完成（可以访问当前this实例）
    created() {

    },
};
</script>
<style lang="scss">
@mixin text-ellipsis {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

@mixin text-ellipsisclamp($clamp) {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: $clamp;
    overflow: hidden;
}

@mixin transition {
    transition: all .3s;
}

.SendResume {
    .box {
        height: auto;
        overflow: hidden;

        .title {
            font-size: 14px;
            color: #999;
            margin-bottom: 15px;
        }

        .el-input__inner {
            width: 310px;
        }

        .btns {
            height: auto;
            overflow: hidden;
            margin-top: 30px;
            text-align: center;

            button {
                width: 120px;
                margin: 0 15px;
            }
        }

        .adjust {
            margin-top: 20px;
            height: auto;
            overflow: hidden;
            padding: 0 20px;

            span {
                font-size: 14px;
                color: #999;
            }
        }
    }

    .box1 {
        text-align: center;

        .title {
            font-size: 18px;
            color: #333;
            margin-bottom: 20px;

            i {
                font-size: 26px;
                color: #67C23A;
                vertical-align: -2px;
                margin-right: 10px;
            }
        }

        p {
            font-size: 14px;
            line-height: 30px;
            text-align: center;

            img {
                width: 120px;
                display: block;
                margin: 10px auto;
            }
        }
    }
}
</style>
